from SysDB import model_to_dict
from SysDB.db_tables_test1 import TablesTest1


def sys_server_table_test1_add(nike_name):
    new_data = TablesTest1(nike_name)
    new_data.save()
    return new_data


def sys_server_table_test1_get_by_nike_name(nike_name):
    return TablesTest1.query.filter(TablesTest1.nike_name == nike_name).first()


def sys_server_amazon_order_get_all(page, size):
    sql = TablesTest1.query
    total = sql.count()
    items = sql.order_by(TablesTest1.created_at.desc()).limit(size).offset((page - 1) * size).all()
    return total, model_to_dict(items)


def sys_server_amazon_order_get_all():
    sql = TablesTest1.query
    items = sql.order_by(TablesTest1.created_at.desc()).all()
    return model_to_dict(items)
